<template>
  <div class="block-management">
    <!-- 页面头部 -->
    <div class="page-header">
      <div class="header-left">
        <h1 class="page-title">区块内容管理</h1>
        <p class="page-desc">管理已定义区块的内容数据（区块结构管理请前往：配置管理 > 区块设置）</p>
      </div>
      <div class="header-actions">
        <el-dropdown @command="handleColumnCommand">
          <el-button class="column-btn">
            <el-icon><Setting /></el-icon>
            字段配置
          </el-button>
          <template #dropdown>
            <el-dropdown-menu>
              <el-dropdown-item
                v-for="column in availableColumns"
                :key="column.key"
                :command="column.key"
              >
                <el-checkbox
                  :model-value="visibleColumns.includes(column.key)"
                  @change="toggleColumn(column.key)"
                >
                  {{ column.label }}
                </el-checkbox>
              </el-dropdown-item>
            </el-dropdown-menu>
          </template>
        </el-dropdown>

      </div>
    </div>

    <!-- 搜索筛选 -->
    <div class="search-section">
      <el-form :model="searchForm" inline>
        <el-form-item label="站点">
          <el-select v-model="searchForm.siteId" placeholder="请选择站点" clearable style="width: 200px">
            <el-option
              v-for="site in sites"
              :key="site.id"
              :label="site.name"
              :value="site.id"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="区块名称">
          <el-input
            v-model="searchForm.name"
            placeholder="请输入区块名称"
            clearable
            style="width: 200px"
          />
        </el-form-item>
        <el-form-item label="区块类型">
          <el-select v-model="searchForm.type" placeholder="请选择类型" clearable style="width: 150px">
            <el-option label="HTML" value="html" />
            <el-option label="文本" value="text" />
            <el-option label="图片" value="image" />
            <el-option label="视频" value="video" />
            <el-option label="列表" value="list" />
            <el-option label="新闻" value="news" />
            <el-option label="公告" value="announcement" />
            <el-option label="应用领域" value="application" />
            <el-option label="会议" value="conference" />
            <el-option label="活动" value="activity" />
            <el-option label="讨论" value="discussion" />
            <el-option label="问题征集" value="collection" />
            <el-option label="合作单位" value="cooperation" />
            <el-option label="自定义" value="custom" />
          </el-select>
        </el-form-item>
        <el-form-item label="状态">
          <el-select v-model="searchForm.status" placeholder="请选择状态" clearable style="width: 120px">
            <el-option label="启用" :value="1" />
            <el-option label="禁用" :value="0" />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="handleSearch">搜索</el-button>
          <el-button type="info" @click="handleReset">重置</el-button>
        </el-form-item>
      </el-form>
    </div>

    <!-- 区块列表 -->
    <div class="table-section">
      <div class="table-container">
        <el-table
          v-loading="loading"
          :data="blockList"
          stripe
          style="width: 100%"
          height="100%"
        >

        <el-table-column v-if="visibleColumns.includes('name')" prop="name" label="区块名称" min-width="150" />
        <el-table-column v-if="visibleColumns.includes('alias')" prop="alias" label="区块别名" min-width="120" />
        <el-table-column v-if="visibleColumns.includes('type')" prop="type" label="类型" width="100" align="center">
          <template #default="{ row }">
            <el-tag :type="getTypeTagType(row.type)">
              {{ getTypeLabel(row.type) }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column v-if="visibleColumns.includes('description')" prop="description" label="描述" min-width="200" show-overflow-tooltip />
        <el-table-column v-if="visibleColumns.includes('fieldConfig')" label="字段配置" min-width="300">
          <template #default="{ row }">
            <div class="field-config-tags">
              <div class="field-row">
                <el-tag v-if="row.hasUrl" size="small" type="primary">链接URL</el-tag>
                <el-tag v-if="row.hasSubtitle" size="small" type="success">副标题</el-tag>
                <el-tag v-if="row.hasSummary" size="small" type="info">摘要</el-tag>
                <el-tag v-if="row.hasImage" size="small" type="warning">图片</el-tag>
              </div>
              <div class="field-row">
                <el-tag v-if="row.hasMobileImage" size="small" type="warning">手机图片</el-tag>
                <el-tag v-if="row.hasVideo" size="small" type="danger">视频</el-tag>
                <el-tag v-if="row.isRecommendable" size="small">可推荐</el-tag>
              </div>
            </div>
          </template>
        </el-table-column>
        <el-table-column v-if="visibleColumns.includes('siteName')" prop="siteName" label="所属站点" width="120" align="center" />
        <el-table-column v-if="visibleColumns.includes('status')" prop="status" label="状态" width="80" align="center">
          <template #default="{ row }">
            <el-switch
              v-model="row.status"
              :active-value="1"
              :inactive-value="0"
              @change="handleStatusChange(row)"
            />
          </template>
        </el-table-column>
        <el-table-column v-if="visibleColumns.includes('orderNum')" prop="orderNum" label="排序" width="80" align="center" />
        <el-table-column v-if="visibleColumns.includes('createDate')" prop="createDate" label="创建时间" width="160" align="center">
          <template #default="{ row }">
            {{ formatDate(row.createDate) }}
          </template>
        </el-table-column>
        <el-table-column label="操作" width="320" fixed="right" align="center">
          <template #default="{ row }">
            <div class="action-buttons">
              <el-button
                type="success"
                size="small"
                @click="handleContent(row)"
                :icon="Document"
                plain
              >
                内容管理
              </el-button>
              <el-button
                type="info"
                size="small"
                @click="handleView(row)"
                :icon="View"
                plain
              >
                预览
              </el-button>

            </div>
          </template>
        </el-table-column>
      </el-table>
      </div>

      <!-- 分页 -->
      <div class="pagination-section">
        <el-pagination
          v-model:current-page="pagination.current"
          v-model:page-size="pagination.size"
          :total="pagination.total"
          :page-sizes="[10, 20, 50, 100]"
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </div>

    <!-- 新增/编辑区块对话框 -->
    <el-dialog
      v-model="dialogVisible"
      :title="dialogTitle"
      width="800px"
      @close="handleDialogClose"
    >
      <el-form
        ref="formRef"
        :model="formData"
        :rules="formRules"
        label-width="100px"
      >
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="区块名称" prop="name">
              <el-input v-model="formData.name" placeholder="请输入区块名称" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="区块别名" prop="alias">
              <el-input v-model="formData.alias" placeholder="请输入区块别名" />
            </el-form-item>
          </el-col>
        </el-row>
        
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="所属站点" prop="siteId">
              <el-select v-model="formData.siteId" placeholder="请选择站点" style="width: 100%">
                <el-option
                  v-for="site in sites"
                  :key="site.id"
                  :label="site.name"
                  :value="site.id"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="区块类型" prop="type">
              <el-select v-model="formData.type" placeholder="请选择类型" style="width: 100%">
                <el-option label="HTML" value="html" />
                <el-option label="文本" value="text" />
                <el-option label="图片" value="image" />
                <el-option label="视频" value="video" />
                <el-option label="列表" value="list" />
                <el-option label="新闻" value="news" />
                <el-option label="公告" value="announcement" />
                <el-option label="应用领域" value="application" />
                <el-option label="会议" value="conference" />
                <el-option label="活动" value="activity" />
                <el-option label="讨论" value="discussion" />
                <el-option label="问题征集" value="collection" />
                <el-option label="合作单位" value="cooperation" />
                <el-option label="自定义" value="custom" />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-form-item label="区块描述">
          <el-input
            v-model="formData.description"
            type="textarea"
            :rows="3"
            placeholder="请输入区块描述"
          />
        </el-form-item>

        <el-form-item label="模板文件">
          <FileManager
            v-model="formData.template"
            file-type="file"
            accept=".ftl,.html,.htm"
            :max-size="2"
            placeholder="选择或上传模板文件"
            tip="支持 .ftl、.html、.htm 格式，最大 2MB"
            upload-button-text="上传模板"
            select-button-text="选择模板"
          />
        </el-form-item>

        <!-- 字段配置 -->
        <div class="form-section">
          <h3 class="section-title">字段配置</h3>

          <!-- 链接URL配置 -->
          <div class="field-config-item">
            <el-row :gutter="20">
              <el-col :span="8">
                <el-form-item label="是否有链接URL">
                  <el-switch v-model="formData.hasUrl" />
                </el-form-item>
              </el-col>
              <el-col :span="8" v-if="formData.hasUrl">
                <el-form-item label="链接URL是否必填">
                  <el-switch v-model="formData.urlRequired" />
                </el-form-item>
              </el-col>
            </el-row>
          </div>

          <!-- 副标题配置 -->
          <div class="field-config-item">
            <el-row :gutter="20">
              <el-col :span="8">
                <el-form-item label="是否有副标题">
                  <el-switch v-model="formData.hasSubtitle" />
                </el-form-item>
              </el-col>
              <el-col :span="8" v-if="formData.hasSubtitle">
                <el-form-item label="副标题是否必填">
                  <el-switch v-model="formData.subtitleRequired" />
                </el-form-item>
              </el-col>
            </el-row>
          </div>

          <!-- 摘要配置 -->
          <div class="field-config-item">
            <el-row :gutter="20">
              <el-col :span="8">
                <el-form-item label="是否有摘要">
                  <el-switch v-model="formData.hasSummary" />
                </el-form-item>
              </el-col>
              <el-col :span="8" v-if="formData.hasSummary">
                <el-form-item label="摘要是否必填">
                  <el-switch v-model="formData.summaryRequired" />
                </el-form-item>
              </el-col>
            </el-row>
          </div>

          <!-- 图片配置 -->
          <div class="field-config-item">
            <el-row :gutter="20">
              <el-col :span="8">
                <el-form-item label="是否有图片">
                  <el-switch v-model="formData.hasImage" />
                </el-form-item>
              </el-col>
              <el-col :span="8" v-if="formData.hasImage">
                <el-form-item label="图片是否必填">
                  <el-switch v-model="formData.imageRequired" />
                </el-form-item>
              </el-col>
            </el-row>
          </div>

          <!-- 手机端图片配置 -->
          <div class="field-config-item">
            <el-row :gutter="20">
              <el-col :span="8">
                <el-form-item label="是否有手机端图片">
                  <el-switch v-model="formData.hasMobileImage" />
                </el-form-item>
              </el-col>
              <el-col :span="8" v-if="formData.hasMobileImage">
                <el-form-item label="手机端图片是否必填">
                  <el-switch v-model="formData.mobileImageRequired" />
                </el-form-item>
              </el-col>
            </el-row>
          </div>

          <!-- 视频配置 -->
          <div class="field-config-item">
            <el-row :gutter="20">
              <el-col :span="8">
                <el-form-item label="是否有视频">
                  <el-switch v-model="formData.hasVideo" />
                </el-form-item>
              </el-col>
              <el-col :span="8" v-if="formData.hasVideo">
                <el-form-item label="视频是否必填">
                  <el-switch v-model="formData.videoRequired" />
                </el-form-item>
              </el-col>
            </el-row>
          </div>

          <!-- 其他配置 -->
          <div class="field-config-item">
            <el-row :gutter="20">
              <el-col :span="8">
                <el-form-item label="是否可推荐">
                  <el-switch v-model="formData.isRecommendable" />
                </el-form-item>
              </el-col>
            </el-row>
          </div>
        </div>

        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="排序号">
              <el-input-number
                v-model="formData.orderNum"
                :min="0"
                :max="999999"
                style="width: 100%"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="状态">
              <el-radio-group v-model="formData.status">
                <el-radio :label="1">启用</el-radio>
                <el-radio :label="0">禁用</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>

      <template #footer>
        <div class="dialog-footer">
          <el-button type="info" @click="dialogVisible = false">取消</el-button>
          <el-button type="primary" @click="handleSubmit" :loading="submitting">
            确定
          </el-button>
        </div>
      </template>
    </el-dialog>

    <!-- 预览对话框 -->
    <el-dialog
      v-model="previewVisible"
      title="区块预览"
      width="600px"
    >
      <div class="preview-content" v-html="previewContent"></div>
    </el-dialog>
  </div>
</template>

<script setup lang="ts">
import { ref, reactive, onMounted, computed } from 'vue'
import { useRouter } from 'vue-router'
import { ElMessage, ElMessageBox } from 'element-plus'
import { Plus, Edit, Document, View, Delete, Setting } from '@element-plus/icons-vue'
import FileManager from '@/components/FileManager/index.vue'
import { blockApi } from '@/api/block'

const router = useRouter()

// 响应式数据
const loading = ref(false)
const submitting = ref(false)
const dialogVisible = ref(false)
const previewVisible = ref(false)
const previewContent = ref('')

// 搜索表单
const searchForm = reactive({
  siteId: '',
  name: '',
  type: '',
  status: ''
})

// 分页数据
const pagination = reactive({
  current: 1,
  size: 20,
  total: 0
})

// 表单数据
const formData = reactive({
  id: null,
  siteId: '',
  name: '',
  alias: '',
  description: '',
  type: 'html',
  orderNum: 0,
  status: 1,
  // 字段配置
  hasUrl: false,
  urlRequired: false,
  hasSubtitle: false,
  subtitleRequired: false,
  hasSummary: false,
  summaryRequired: false,
  hasImage: false,
  imageRequired: false,
  hasMobileImage: false,
  mobileImageRequired: false,
  hasVideo: false,
  videoRequired: false,
  isRecommendable: false
})

// 表单验证规则
const formRules = {
  name: [
    { required: true, message: '请输入区块名称', trigger: 'blur' }
  ],
  alias: [
    { required: true, message: '请输入区块别名', trigger: 'blur' }
  ],
  siteId: [
    { required: true, message: '请选择所属站点', trigger: 'change' }
  ],
  type: [
    { required: true, message: '请选择区块类型', trigger: 'change' }
  ]
}

// 数据列表
const blockList = ref([])
const sites = ref([])
const templateFiles = ref([])

// 字段配置
const availableColumns = ref([
  { key: 'name', label: '区块名称' },
  { key: 'alias', label: '区块别名' },
  { key: 'type', label: '类型' },
  { key: 'description', label: '描述' },
  { key: 'fieldConfig', label: '字段配置' },
  { key: 'siteName', label: '所属站点' },
  { key: 'status', label: '状态' },
  { key: 'orderNum', label: '排序' },
  { key: 'createDate', label: '创建时间' }
])

const visibleColumns = ref(['name', 'alias', 'type', 'description', 'fieldConfig', 'siteName', 'status', 'orderNum', 'createDate'])

// 计算属性
const dialogTitle = computed(() => {
  return formData.id ? '编辑区块' : '新增区块'
})

// 字段配置方法
const toggleColumn = (columnKey: string) => {
  const index = visibleColumns.value.indexOf(columnKey)
  if (index > -1) {
    visibleColumns.value.splice(index, 1)
  } else {
    visibleColumns.value.push(columnKey)
  }
}

const handleColumnCommand = (command: string) => {
  // 这里可以处理其他命令，目前主要通过checkbox处理
}

// 方法
const getTypeLabel = (type: string) => {
  const typeMap = {
    html: 'HTML',
    text: '文本',
    image: '图片',
    video: '视频',
    list: '列表',
    custom: '自定义'
  }
  return typeMap[type] || type
}

const getTypeTagType = (type: string) => {
  const typeMap = {
    html: 'primary',
    text: 'success',
    image: 'warning',
    video: 'danger',
    list: 'info',
    custom: ''
  }
  return typeMap[type] || ''
}

const formatDate = (date: string) => {
  if (!date) return ''
  return new Date(date).toLocaleString()
}

// 加载数据
const loadData = async () => {
  loading.value = true
  try {
    // 构建查询参数，过滤掉空值
    const params: any = {
      current: pagination.current,
      size: pagination.size
    }

    // 只添加有值的搜索参数
    if (searchForm.siteId !== undefined && searchForm.siteId !== null && searchForm.siteId !== '') {
      params.siteId = searchForm.siteId
    }
    if (searchForm.name && searchForm.name.trim()) {
      params.name = searchForm.name.trim()
    }
    if (searchForm.type && searchForm.type.trim()) {
      params.type = searchForm.type.trim()
    }
    if (searchForm.status !== undefined && searchForm.status !== null && searchForm.status !== '') {
      params.status = searchForm.status
    }

    // 使用blockApi获取区块列表
    const response = await blockApi.getList(params)
    console.log('区块列表响应:', response)

    if (response.code === 0) {
      blockList.value = response.data?.records || response.data?.list || []
      pagination.total = response.data?.total || 0
    } else {
      console.warn('获取区块数据失败:', response.msg)
      blockList.value = []
      pagination.total = 0
      ElMessage.warning(response.msg || '获取区块数据失败')
    }

  } catch (error) {
    console.error('加载区块数据失败:', error)
    ElMessage.error('加载区块数据失败，请检查网络连接')
    blockList.value = []
    pagination.total = 0
  } finally {
    loading.value = false
  }
}

// 加载站点列表
const loadSites = async () => {
  try {
    const response = await blockApi.getSiteList()
    if (response.code === 0) {
      sites.value = response.data || []
    } else {
      // 使用模拟数据作为后备
      sites.value = [
        { id: 1, name: '主站' },
        { id: 2, name: '移动站' }
      ]
    }
  } catch (error) {
    console.error('加载站点列表失败:', error)
    // 使用模拟数据作为后备
    sites.value = [
      { id: 1, name: '主站' },
      { id: 2, name: '移动站' }
    ]
  }
}

// 加载模板文件列表
const loadTemplateFiles = async () => {
  try {
    const response = await blockApi.getTemplateList()
    if (response.code === 0) {
      templateFiles.value = response.data || []
    } else {
      // 使用模拟数据作为后备
      templateFiles.value = [
        { name: 'block/header.ftl', path: 'block/header.ftl' },
        { name: 'block/footer.ftl', path: 'block/footer.ftl' },
        { name: 'block/sidebar.ftl', path: 'block/sidebar.ftl' },
        { name: 'block/banner.ftl', path: 'block/banner.ftl' },
        { name: 'block/nav.ftl', path: 'block/nav.ftl' }
      ]
    }
  } catch (error) {
    console.error('加载模板文件失败:', error)
    // 使用模拟数据作为后备
    templateFiles.value = [
      { name: 'block/header.ftl', path: 'block/header.ftl' },
      { name: 'block/footer.ftl', path: 'block/footer.ftl' },
      { name: 'block/sidebar.ftl', path: 'block/sidebar.ftl' },
      { name: 'block/banner.ftl', path: 'block/banner.ftl' },
      { name: 'block/nav.ftl', path: 'block/nav.ftl' }
    ]
  }
}

// 搜索
const handleSearch = () => {
  pagination.current = 1
  loadData()
}

// 重置
const handleReset = () => {
  Object.assign(searchForm, {
    siteId: '',
    name: '',
    type: '',
    status: ''
  })
  handleSearch()
}

// 状态切换
const handleStatusChange = async (row: any) => {
  try {
    const response = await blockApi.updateStatus(row.id, row.status)
    if (response.code === 0) {
      ElMessage.success('状态更新成功')
    } else {
      row.status = row.status === 1 ? 0 : 1 // 回滚状态
      ElMessage.error(response.msg || '状态更新失败')
    }
  } catch (error) {
    row.status = row.status === 1 ? 0 : 1 // 回滚状态
    ElMessage.error('状态更新失败')
  }
}

// 显示新增对话框 - 已禁用，请前往配置管理
// const showAddDialog = () => {
//   Object.assign(formData, {
//     id: null,
//     siteId: '',
//     name: '',
//     alias: '',
//     description: '',
//     type: 'html',
//     template: '',
//     content: '',
//     orderNum: 0,
//     status: 1
//   })
//   dialogVisible.value = true
// }

// 编辑 - 已禁用，请前往配置管理
// const handleEdit = (row: any) => {
//   Object.assign(formData, { ...row })
//   dialogVisible.value = true
// }

// 内容管理
const handleContent = (row: any) => {
  router.push(`/content/block/content/${row.id}`)
}

// 预览
const handleView = async (row: any) => {
  try {
    // 获取区块的实际渲染内容
    const response = await blockApi.getBlockRenderData(row.id)
    if (response.code === 0) {
      const renderData = response.data
      // 构建预览HTML
      let previewHtml = '<div class="block-preview">'

      if (renderData.items && renderData.items.length > 0) {
        previewHtml += '<h4>区块内容：</h4>'
        renderData.items.forEach((item: any, index: number) => {
          previewHtml += `<div class="block-item" style="margin-bottom: 15px; padding: 10px; border: 1px solid #eee; border-radius: 4px;">`
          previewHtml += `<div style="font-weight: bold; margin-bottom: 5px;">内容项 ${index + 1}</div>`

          if (item.title) {
            previewHtml += `<div><strong>标题：</strong>${item.title}</div>`
          }
          if (item.subtitle) {
            previewHtml += `<div><strong>副标题：</strong>${item.subtitle}</div>`
          }
          if (item.imageUrl) {
            previewHtml += `<div><strong>图片：</strong><br><img src="${item.imageUrl}" style="max-width: 200px; max-height: 150px; object-fit: cover;" /></div>`
          }
          if (item.linkUrl) {
            previewHtml += `<div><strong>链接：</strong><a href="${item.linkUrl}" target="_blank">${item.linkUrl}</a></div>`
          }
          if (item.content) {
            previewHtml += `<div><strong>内容：</strong>${item.content}</div>`
          }

          previewHtml += '</div>'
        })
      } else {
        previewHtml += '<div style="color: #999; text-align: center; padding: 20px;">该区块暂无内容项</div>'
      }

      previewHtml += '</div>'
      previewContent.value = previewHtml
    } else {
      previewContent.value = row.content || '暂无内容'
    }
  } catch (error) {
    console.error('获取区块渲染数据失败:', error)
    previewContent.value = row.content || '暂无内容'
  }

  previewVisible.value = true
}

// 删除 - 已禁用，请前往配置管理
// const handleDelete = async (row: any) => {
//   try {
//     await ElMessageBox.confirm('确定要删除这个区块吗？', '提示', {
//       confirmButtonText: '确定',
//       cancelButtonText: '取消',
//       type: 'warning'
//     })

//     const response = await blockApi.delete(row.id)
//     if (response.code === 0) {
//       ElMessage.success('删除成功')
//       loadData()
//     } else {
//       ElMessage.error(response.msg || '删除失败')
//     }
//   } catch (error) {
//     if (error !== 'cancel') {
//       ElMessage.error('删除失败')
//     }
//   }
// }

// 提交表单
const handleSubmit = async () => {
  submitting.value = true
  try {
    const isEdit = !!formData.id
    const response = isEdit
      ? await blockApi.update(formData)
      : await blockApi.create(formData)

    if (response.code === 0) {
      ElMessage.success(isEdit ? '更新成功' : '创建成功')
      dialogVisible.value = false
      loadData()
    } else {
      ElMessage.error(response.msg || '保存失败')
    }
  } catch (error) {
    ElMessage.error('保存失败')
  } finally {
    submitting.value = false
  }
}

// 对话框关闭
const handleDialogClose = () => {
  // TODO: 重置表单
}

// 分页
const handleSizeChange = (size: number) => {
  pagination.size = size
  loadData()
}

const handleCurrentChange = (current: number) => {
  pagination.current = current
  loadData()
}

// 生命周期
onMounted(() => {
  loadSites()
  loadTemplateFiles()
  loadData()
})
</script>

<style scoped lang="scss">
.block-management {
  height: calc(100vh - 120px);
  display: flex;
  flex-direction: column;
  padding: 0;
  margin: 0;
  background: #f0f2f5;
  overflow: hidden;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 20px;
  padding: 20px 20px 0 20px;

  .header-left {
    .page-title {
      font-size: 24px;
      font-weight: 600;
      color: #2c3e50;
      margin: 0 0 6px 0;
    }

    .page-desc {
      font-size: 14px;
      color: #6c757d;
      margin: 0;
    }
  }
}

.search-section {
  background: white;
  padding: 20px;
  margin: 0 20px 20px 20px;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.table-section {
  flex: 1;
  background: white;
  margin: 0 20px 20px 20px;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;

  .table-container {
    flex: 1;
    overflow: hidden;
    padding: 0;

    .el-table {
      height: 100%;
    }
  }
}

.pagination-section {
  display: flex;
  justify-content: center;
  padding: 16px;
  border-top: 1px solid #ebeef5;
  background: white;
  flex-shrink: 0;
}

.preview-content {
  max-height: 400px;
  overflow-y: auto;
  padding: 10px;
  border: 1px solid #dcdfe6;
  border-radius: 4px;
  background: #f5f7fa;
}

// 字段配置标签样式
.field-config-tags {
  display: flex;
  flex-direction: column;
  gap: 6px;

  .field-row {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
  }

  .el-tag {
    margin: 0;
    font-size: 11px;
    height: 20px;
    line-height: 18px;
  }
}

// 表单分组样式
.form-section {
  margin-bottom: 24px;
  padding: 16px;
  background: #f8f9fa;
  border-radius: 6px;

  .section-title {
    margin: 0 0 16px 0;
    font-size: 16px;
    font-weight: 600;
    color: #303133;
    border-bottom: 2px solid #409eff;
    padding-bottom: 8px;
  }

  .field-config-item {
    margin-bottom: 16px;
    padding: 12px;
    background: white;
    border-radius: 4px;
    border: 1px solid #e4e7ed;

    &:last-child {
      margin-bottom: 0;
    }
  }
}

// 操作按钮样式
.action-buttons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;

  .el-button {
    border-radius: 6px;
    font-weight: 500;
    transition: all 0.3s ease;
    border: 1px solid transparent;

    &:hover {
      transform: translateY(-1px);
      box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    }
  }

  // 编辑按钮 - 蓝色系
  .edit-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;

    &:hover {
      background: linear-gradient(135deg, #5a6fd8 0%, #6a4190 100%);
    }
  }

  // 内容管理按钮 - 绿色系
  .content-btn {
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    color: white;
    border: none;

    &:hover {
      background: linear-gradient(135deg, #3d8bfe 0%, #00d4fe 100%);
    }
  }

  // 预览按钮 - 灰色系
  .preview-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    opacity: 0.8;

    &:hover {
      background: linear-gradient(135deg, #5a6fd8 0%, #6a4190 100%);
      opacity: 1;
    }
  }

  // 删除按钮 - 红色系
  .delete-btn {
    background: linear-gradient(135deg, #ff6b6b 0%, #ee5a52 100%);
    color: white;
    border: none;

    &:hover {
      background: linear-gradient(135deg, #ff5252 0%, #e53935 100%);
    }
  }
}
</style>
